#include "iTube.h"

#include "RenameDlg.h"
#include "fileversion.h"

				//child         //parent (from iTube_GUI)
BEGIN_EVENT_TABLE( RenameDlg,RenameDialog )
	
EVT_BUTTON( ID_RNDI_OK_BUTTON, RenameDlg::OnRenameButtonClick )

END_EVENT_TABLE()


//class: RenameDlg
//function: RenameDlg
//Use: Init the dialog, fill the text box with "renameBox"
//renameBox should be the file name that it was downloaded with (The YouTube ID)

RenameDlg::RenameDlg(  wxWindow* parent, wxString renameBox )
	: RenameDialog( parent,-1,wxT("Rename Video?"),wxDefaultPosition, wxDefaultSize,wxCAPTION | wxCLOSE_BOX, renameBox  )
{

ws_oldName = renameBox;

	wxMessageBox(wxT("RenameDialog has been created"));
	}

RenameDlg::~RenameDlg()
	{
	this->Destroy();
	}

void RenameDlg::OnRenameButtonClick(wxCommandEvent& event)
	{
	//the rename function will accept paths.  We will leave this
	//in since there is currently no feature to save to a specific directory automatically
	
	
	ws_newName = Filename_Input->GetValue();
	if(ws_newName.Len() > 100){
		wxMessageBox(wxT("Filename too long.  Stop trying to break the program!"));
		ws_newName == ws_oldName;	
		}

	//convert ws_oldName to char*
	char c_oldName[100];
	strcpy(c_oldName,(const char*)ws_oldName.mb_str(wxConvUTF8));

	//convert ws_newName to char*
	char* c_newName[100];
	strcpy((char*)c_newName,(const char*)ws_newName.mb_str(wxConvUTF8));

	int result = rename(c_oldName,((char*)c_newName));

	if (result != 0){
		wxMessageBox(wxT("Error renaming file.  Check to make sure the file is not in use or write protected."));
		}


	


	}

